<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/layui/layui.js"></script>
    <script src="/js/template-web.js"></script>
</head>
<body>

    <div class="layui-container">
        <table class="layui-table">
            <thead>
                <tr>
                    <th>th01</th>
                    <th>th02</th>
                    <th>th03</th>
                </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
    </div>

    <!-- 定义一个模板 -->
    <script id="demo" type="text/html">
        {{ each arr value index }}
        <tr>
            <td>{{ value.id }}</td>
            <td>{{ value.username }}</td>
            <td>{{ value.password }}</td>
        </tr>
        {{ /each }}
    </script>
    <script>
        function sendAjax(){
            let xhr=new XMLHttpRequest();
            xhr.open("get","/getUsers");
            xhr.onload=function(){
                let arr=JSON.parse(xhr.responseText);//array
                let str=template("demo",{arr});//返回的是一个字符串
                let dom=document.querySelector("tbody");
                dom.innerHTML=str;
            };
            xhr.send();
        }
        sendAjax();
    </script>
</body>
</html>